#pragma once

#include <iostream>
#include <string>
#include <functional>
#include <pthread.h>
#include "log.hpp"


//using callback_t = std::function<void (std::string, uint32_t,int)>;
//每一个线程的任务是与客户端通信
class task
{
public:
    using callback_t = std::function<void (std::string, uint32_t,int)>;
    //构造函数
    task(std::string clientip, uint32_t clientport,int sock,callback_t func)
        :clientip_(clientip),clientport_(clientport),sock_(sock),func_(func)
    {}
    task():sock_(-1), clientport_(-1)
    {}
    void operator()()
    {
        logMessage(DEBUG, "线程ID[%p]处理%s:%d的请求 开始...",pthread_self(), clientip_.c_str(), clientport_);
        func_(clientip_,clientport_,sock_);
        logMessage(DEBUG, "线程ID[%p]处理%s:%d的请求 结束...",pthread_self(), clientip_.c_str(), clientport_);
    }
 
private:
    int sock_;
    std::string clientip_;
    uint32_t clientport_;
    callback_t func_;
};
